package com.cet.lxf.collection.test06;

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

/**
 * @program: algorithm
 * @description:
 * @author: 陈恩涛
 * @create: 2021-08-10 10:49
 **/
public class Main {
    public static void main(String[] args) {
        Map<Person, Integer> map = new TreeMap<>(Comparator.comparing(Person::getName));

        map.put(new Person("Tom"), 1);
        map.put(new Person("Bob"), 2);
        map.put(new Person("Lily"), 3);
        for (Person key : map.keySet()) {
            System.out.println(key);
        }
        // {Person: Bob}, {Person: Lily}, {Person: Tom}
        System.out.println(map.get(new Person("Bob"))); // 2
    }
}

class Person {
    public String name;
    Person(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return "{Person: " + name + "}";
    }
}
